﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ATest.Bll.Interfaces;
using ATest.Bll.Repositories;

namespace ATest.Tests.RepositoryTests
{
    [TestClass]
    public class TestRepositoryTest
    {
        private ITestRepository _TestRepository;
        private List<MockObjects.MockTest> _TestData;
        [TestInitialize]
        public void Init()
        {
            _TestData = MockObjects.MockTest.CreateList(5);
            _TestRepository = new TestRepository(_TestData.Select(x => x.Object).AsQueryable());
        }

        [TestMethod]
        public void GetById_WithInvalidId_ReturnsNull()
        {
            var tmp = _TestRepository.GetById(0);

            Assert.IsNull(tmp);
        }

        [TestMethod]
        public void GetById_WithValidId_ReturnsCorrectTest()
        {
            var tmp = _TestRepository.GetById(_TestData.Last().Object.Id);

            Assert.IsNotNull(tmp);

            Assert.AreEqual(_TestData.Last().Object, tmp);
        }

        [TestMethod]
        public void GetAll_ReturnsTests()
        {
            var tmp = _TestRepository.GetAll();

            Assert.IsNotNull(tmp);

            Assert.AreEqual(_TestData.Count, tmp.Count());
        }

        [TestMethod]
        public void GetAll_DoesNotReturnDeleted()
        {
            _TestData.First().Setup(x => x.Deleted).Returns(true);

            var tmp = _TestRepository.GetAll();

            Assert.IsNotNull(tmp);

            Assert.AreEqual(_TestData.Count - 1, tmp.Count());

        }
    }

}
